
USE [GenericBroker]

-- Create [Packets]
IF OBJECT_ID('[dbo].[Packets]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Packets]
GO

CREATE TABLE [dbo].[Packets](
	[Id]						[int] IDENTITY(1,1) NOT NULL,
	[IPAddress]					[nvarchar](50) NULL,
	[Direction]					[nvarchar](50) NULL,
	[Data]						[ntext] NULL,
	[ServiceClass]				[nvarchar](50) NULL,
	[InvocationMethod]			[nvarchar](50) NULL,
	[InvocationMethodResult]	[ntext] NULL,
	[Status]					[nvarchar](50) NULL,
	[Message]					[nvarchar](500) NULL,
	[Created]					[datetime] NULL,
	[CreatedBy]					[nvarchar](50) NULL,
 CONSTRAINT [PK_ApplicationLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[Packets] ADD  CONSTRAINT [DF_Packets_Created]  DEFAULT (GETDATE()) FOR [Created]
GO

CREATE NONCLUSTERED INDEX [IX_Packets_1] ON [dbo].[Packets] 
(
	[IPAddress] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [IX_Packets_2] ON [dbo].[Packets] 
(
	[Direction] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [IX_Packets_3] ON [dbo].[Packets] 
(
	[ServiceClass] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [IX_Packets_4] ON [dbo].[Packets] 
(
	[InvocationMethod] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

CREATE NONCLUSTERED INDEX [IX_Packets_5] ON [dbo].[Packets] 
(
	[Status] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

-- Create [PacketData]
IF OBJECT_ID('[dbo].[PacketData]', 'U') IS NOT NULL
	DROP TABLE [dbo].[PacketData]
GO

CREATE TABLE [dbo].[PacketData](
	[Id]			[int] IDENTITY(1,1) NOT NULL,
	[PacketId]		[int] NOT NULL,
	[Key]			[nvarchar](400) NULL,
	[Value]			[ntext] NULL,
	[Created]		[datetime] NULL,
	[CreatedBy]		[nvarchar](50) NULL,
 CONSTRAINT [PK_PacketData] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[PacketData] ADD  CONSTRAINT [DF_PacketData_Created]  DEFAULT (GETDATE()) FOR [Created]
GO

CREATE NONCLUSTERED INDEX [IX_PacketData_1] ON [dbo].[PacketData] 
(
	[PacketId] ASC,
	[Key] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]
GO
